package com.wilcom.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wilcom.system.common.ErrorCode;
import com.wilcom.system.domain.Maintenance;
import com.wilcom.system.exception.BusinessException;
import com.wilcom.system.exception.ThrowUtils;
import com.wilcom.system.service.MaintenanceService;
import com.wilcom.system.mapper.MaintenanceMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wilcom.system.model.request.repairrequest.MaintenanceQueryRequest;

/**
 * @author lishi
 * @description 针对表【maintenance】的数据库操作Service实现
 * @createDate 2024-06-21 17:25:38
 */
@Service
public class MaintenanceServiceImpl extends ServiceImpl<MaintenanceMapper, Maintenance>
        implements MaintenanceService {

    @Override
    public QueryWrapper<Maintenance> getQueryWrapper(MaintenanceQueryRequest postQueryRequest) {
        QueryWrapper<Maintenance> queryWrapper = new QueryWrapper<>();
        if (postQueryRequest == null) {
            return queryWrapper;
        }
        return queryWrapper;
    }

    @Override
    public void validMaintenance(Maintenance post, boolean add) {
        if (post == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        String urgency = post.getUrgency();
        String location = post.getLocation();
        String faultDescription = post.getFaultDescription();
        Integer taskStatus = post.getTaskStatus();
        Integer userID = post.getUserID();



        // 创建时，参数不能为空
        if (add) {
            ThrowUtils.throwIf(StringUtils.isAnyBlank(location, urgency, faultDescription), ErrorCode.PARAMS_ERROR);
        }
        // 有参数则校验
//        if (StringUtils.isNotBlank(title) && title.length() > 80) {
//            throw new BusinessException(ErrorCode.PARAMS_ERROR, "标题过长");
//        }
//        if (StringUtils.isNotBlank(content) && content.length() > 8192) {
//            throw new BusinessException(ErrorCode.PARAMS_ERROR, "内容过长");
//        }
    }
}




